package com.sskj.functions.presenter;

import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.functions.activity.PledgeActivity;
import com.sskj.functions.presenter.BasePresenter;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.bean.CurrentTypeBean;
import com.sskj.lib.bean.PledgeBean;
import com.sskj.lib.bean.PledgeInterestBean;
import com.sskj.lib.http.JsonCallBack;

import org.jsoup.Connection;

import java.util.List;

/**
 * @author Hey
 * Create at  2019/06/26
 */
public class PledgePresenter extends BasePresenter<PledgeActivity> {

    public void getPledgeInterest(String tv) {
        httpService.getPledgeInterest(tv)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PledgeInterestBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PledgeInterestBean>> response) {
                        PledgeInterestBean data = response.body().getData();
                        mView.getPledgeInterestSuccess(data);
                    }
                });
    }

    public void startPledge(String tv1, String pledgeStateOne, String s1, String pledgeStateTwo, String string, String toString, String procedures, String s, String tv, String pwd) {
        httpService.startPledge(tv1, pledgeStateOne, s1, pledgeStateTwo, string, toString, procedures, s, tv, MD5Util.getFiveMd5Value(pwd))
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        ToastUtils.show(response.body().msg);
                        if (response.body().status == BaseHttpConfig.OK) {
                            mView.finish();
                        }
                    }
                });
    }

    public void getCurrentType() {
        httpService.getCurrentType()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<String>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<String>>> response) {
                        List<String> data = response.body().getData();
                        mView.getCurrentTypeSuccess(data);
                    }
                });
    }


    public void getTimeData(String languages) {
        httpService.getTimeData(languages)
                .tag(this)
                .execute(new JsonCallBack<HttpData<PledgeBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<PledgeBean>> response) {
                        PledgeBean data = response.body().getData();
                        mView.getPledgeData(data);
                    }
                });
    }
}
